package com.xzq.socket.bio.server;

import com.xzq.socket.bio.ChannelAdapter;
import com.xzq.socket.bio.ChannelHandler;

import java.net.Socket;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/17 16:48
 * @Version 1.0.0
 **/
public class BioServerHandler extends ChannelAdapter {


    public BioServerHandler(Socket socket, Charset charset) {
        super(socket, charset);
    }

    @Override
    public void channelActive(ChannelHandler channelHandler) {
        System.out.println("链接报告LocalAddress:"+channelHandler.getSocket().getLocalAddress());
        channelHandler.writeAndFlush("hi I am Server");
    }

    @Override
    public void channelRead(ChannelHandler ctx, Object msg) {
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "接收到消息：" + msg);
        ctx.writeAndFlush("已接收到消息!\r\n");
    }
}
